package com.pagepub.core.tag.validator;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

public class ValidateNomalKeyword extends FormValidateBasic {
	private static final long serialVersionUID = -9063004980334045055L;

	private String callfuntionaname;

	private String functionname;

	private String rightimage;

	private String submitvalidate;

	private String rightwordcolor;

	public String getFunctionname() {
		return functionname;
	}

	public void setFunctionname(String functionname) {
		this.functionname = functionname;
	}

	public String getRightimage() {
		return rightimage;
	}

	public void setRightimage(String rightimage) {
		this.rightimage = rightimage;
	}

	public String getRightwordcolor() {
		return rightwordcolor;
	}

	public void setRightwordcolor(String rightwordcolor) {
		this.rightwordcolor = rightwordcolor;
	}

	public String getSubmitvalidate() {
		return submitvalidate;
	}

	public void setSubmitvalidate(String submitvalidate) {
		this.submitvalidate = submitvalidate;
	}

	public String getCallfuntionaname() {
		return callfuntionaname;
	}

	public void setCallfuntionaname(String callfuntionaname) {
		this.callfuntionaname = callfuntionaname;
	}

	public int doStartTag() throws JspException {
		JspWriter out = this.pageContext.getOut();
		StringBuffer str = new StringBuffer();
		ValidateEmpty validateempty = new ValidateEmpty();
		validateempty.setWordcolor(wordcolor);
		validateempty.setWrongimage(wrongimage);

		ValidateLength validateLength = new ValidateLength();
		validateLength.setWordcolor(wordcolor);
		validateLength.setWrongimage(wrongimage);
		IsExit isexit = new IsExit();
		isexit.setCallfuntionaname(callfuntionaname);
		this.setFunctionname("validatenormalkeywordexit");
		isexit.setFunctionname(functionname);
		isexit.setSubmitvalidate(submitvalidate);
		isexit.setRightimage(rightimage);
		isexit.setWordcolor(wordcolor);
		isexit.setWrongimage(wrongimage);
		isexit.setRightwordcolor(rightwordcolor);
		// TODO 自动生成方法存根
		str.append(validateempty.validateempty());
		str.append(validateLength.validatelength());
		str.append(isexit.isexit());
		str.append(validatenomalkeyword());
		try {

			out.print(str);
			// System.out.println(str);
		} catch (IOException e) {
			// TODO 自动生成 catch 块

			e.printStackTrace();
		}
		return 1;
	}

	public StringBuffer validatenomalkeyword() {
		StringBuffer str = new StringBuffer();
		// String emptyelement="";
		String pluselement = "";
		if (this.submitvalidate.equalsIgnoreCase("true")) {
			// emptyelement="emptyelement(realname);";
			pluselement = "else pluselement(realname);";
		}
		str.append("<script language=\"javascript\">");
		// realvalue当前验证值 spanname 显示span 的id realname显示的名称 nextelmentname
		// 下一个要验证的元素
		str
				.append("function validatenormalkeyword(realvalue,minlenth,maxlenth,spanname,realname,callfunvalue) {");
		// str.append("alert(spanname);");
		str.append("if(Validateempty(realvalue,realname,spanname))");
		str
				.append(" if(ValidateLength(realvalue,minlenth,maxlenth,realname,spanname))");
		str
				.append("validatenormalkeywordexit(realvalue,spanname,realname,callfunvalue);");
		str.append(pluselement);
		str.append(pluselement);
		str.append("}");
		str.append("</script>");
		return str;
	}
}
